home *** CD-ROM | disk | FTP | other *** search
- MODULE Cat; (* send a file to printer or screen *)
- FROM InOut IMPORT ReadString, EOL, Done, OpenInputFile,
- CloseInput, Read, Write, WriteLn, WriteString, WriteInt;
- FROM Streams IMPORT Stream, StreamKinds, OpenStream, CloseStream, EOS;
- FROM TextIO IMPORT WRite, WRiteLn, WRiteString, WRiteInt, WRiteCard, REad;
- FROM AESForms IMPORT FileSelectorInput, FormAlert;
- FROM GEMDOS IMPORT OldTerm, GetDrv, SetDrv, NecIn;
- FROM MyFiles IMPORT SelectFile, NewPath;
- FROM Environment IMPORT OpenAppl, CloseAppl, CursorOn, CursorOff;
- FROM VDIEscapes IMPORT ReverseVideoOn, ReverseVideoOff, CursorAddress;
- IMPORT ASCII;
- FROM Clock IMPORT FindDate, FindTime;
- CONST MaxInt = 32767;
- TABS = "(008,016,024,032,040,048,056,064,072."; (* for Itoh 8510 *)
- Version =
- "[2][WLS Cat Ver. 0.6|developed with TDI/Modula-2||output to:][printer|screen|file]";
- NoEpson =
- "[1][Epson and compatible printers:|no initialization procedure yet][none]";
-
- TYPE OutputDevice = (printer, screen, file);
- Status = (normal, cr, lf); (* for endline handling *)
- PrinterType = (unknown, itoh, epson, none);
- VAR c : CHAR;
- path, newfile : ARRAY [0..64] OF CHAR;
- Ext : ARRAY [0..3] OF CHAR;
- PageSize, PageNumber, i, column, dot, wh, width, line : INTEGER;
- year, month, day, hour, min, sec, Drive : CARDINAL;
- dummy : LONGCARD;
- InStream, OutStream : Stream;
- Device : OutputDevice;
- Printer : PrinterType;
- Pause, KeepGoing : BOOLEAN;
- lastchar : Status;
-
- PROCEDURE Cls; (* clear the screen, home the cursor *)
- BEGIN
- Write(ASCII.ESC); Write('E');
- END Cls;
-
- PROCEDURE Wrap; (* finish up and exit gracefully *)
- BEGIN
- CursorOn; CloseAppl(wh); OldTerm(); (* KeepGoing := FALSE *)
- END Wrap;
-
- PROCEDURE PutByte(ch : CHAR);
- BEGIN
- WRite(OutStream, ch);
- INC(column);
- END PutByte;
-
- PROCEDURE NewLine;
- BEGIN
- WRiteLn(OutStream);
- IF Device # screen
- THEN Write('.'); INC(dot); (* dot serves as a counter *)
- IF dot > 78 THEN WriteLn; dot := 0 END;
- END; (* something to watch *)
- column := 0; INC(line);
- END NewLine;
-
- PROCEDURE Header; (* used for printer only *)
- BEGIN
- WRiteLn(OutStream);
- WRiteString(OutStream, path); WRiteString(OutStream, " -- ");
- IF year > 85 THEN
- WRiteCard(OutStream, year,2); WRite(OutStream, '/');
- WRiteCard(OutStream, month,1); WRite(OutStream, '/');
- WRiteCard(OutStream, day,1); WRiteString(OutStream, ' ');
- WRiteCard(OutStream, hour,2); WRite(OutStream, ':');
- IF min < 10 THEN WRite(OutStream, '0'); WRiteCard(OutStream, min, 1);
- ELSE WRiteCard(OutStream, min, 2) END;
- WRiteString(OutStream, " -- ");
- END;
- WRiteString(OutStream, "Page ");
- WRiteInt(OutStream, PageNumber, 1);
- WRiteLn(OutStream); WRiteLn(OutStream); (* now write to screen -- *)
- WriteLn; WriteString("Page "); WriteInt(PageNumber, 2); (* display *)
- line := 12; column :=0; INC(PageNumber);
- END Header;
-
- PROCEDURE pass; (* process and output a character *)
- BEGIN
- CASE c OF
- 34C..36C, 40C : PutByte(' '); lastchar := normal |
- ASCII.CR : IF lastchar # lf THEN NewLine; lastchar := cr; END |
- ASCII.LF : IF lastchar # cr THEN NewLine; lastchar := lf; END |
- (* 0C : NewLine; lastchar := normal | STW EOL *)
- ELSE PutByte(c); lastchar := normal
- END;
- IF column >= width THEN NewLine END;
- IF EOS(InStream) THEN Done := FALSE; (* for InOut compatibility *)
- ELSIF line > PageSize THEN
- CASE Device OF
- printer : PutByte(ASCII.FF); Header |
- screen : ReverseVideoOn(wh);
- WriteString("---More---");
- ReverseVideoOff(wh);
- NecIn(c);
- Write(ASCII.ESC); Write('l'); (* erase line *)
- column := 0;
- CASE c OF
- 'q', 'Q' : Done := FALSE; Pause := FALSE |
- 'a', 'A' : Done := FALSE; Pause := FALSE;
- KeepGoing := FALSE |
- EOL : DEC(line) |
- '1'..'9' : DEC(line, ORD(c) - ORD('0')) |
- '?', 'h', 'H' : WriteLn; (* HELP menu *)
- WriteString("Commands are:"); WriteLn;
- WriteString(
- "SPACE for next page, RETURN for next line");
- WriteLn;
- WriteString(
- "Q quits this file, A aborts the program");
- WriteLn;
- WriteString(
- "Enter a digit n to see the next n lines");
- WriteLn;
- c := ' '; pass
- ELSE line := 0
- END |
- file : (* no processing in this case *)
- END
- END;
- END pass;
-
- PROCEDURE OpenDevice() : BOOLEAN ;
- BEGIN
- CursorOff; Cls; CursorAddress(wh, 12, 40); CursorOn;
- i:=FormAlert(1, Version) - 1 ;
- Device := VAL( OutputDevice, i );
- Pause := FALSE;
- CursorOff; Cls; CursorAddress(wh, 12, 40); CursorOn;
- CASE Device OF
- printer : OpenStream(OutStream, "PRN:", READWRITE, i);
- IF i<0 THEN RETURN FALSE; END;
- IF Printer = unknown
- THEN i := FormAlert(3,
- "[2][Printer Initialization][Itoh|Epson|none]");
- Printer := VAL(PrinterType, i);
- CASE Printer OF
- itoh : WRite(OutStream, ASCII.ESC);
- WRiteString(OutStream, TABS) |
- epson : CursorOff; Cls; CursorAddress(wh, 12, 40);
- CursorOn; i := FormAlert(1, NoEpson) |
- none :
- END;
- CursorOff;
- END;
- PageSize := 66; width := 80;
- CursorOff; Cls;
- WriteString("Printing ");
- WriteString(path); WriteLn;
- PageNumber := 1; Header |
- screen : OpenStream(OutStream, "CON:", READWRITE, i);
- IF i<0 THEN RETURN FALSE; END;
- PageSize := 23; width := 79 (* avoid auto-wrap *);
- line := 0; column := 0; Pause := TRUE;
- CursorOff; Cls |
- file : newfile := path;
- CursorAddress(wh, 2, 21); ReverseVideoOn(wh);
- WriteString("Select OUTPUT File...");
- ReverseVideoOff(wh); CursorOff;
- CursorAddress(wh, 12, 40); CursorOn;
- Ext := '*'; NewPath(newfile, Ext);
- IF NOT SelectFile(newfile) THEN Wrap END;
- OpenStream(OutStream, newfile, READWRITE, i);
- IF i<0 THEN RETURN FALSE; END;
- PageSize := MaxInt;
- width := MaxInt; line := 0; column := 0;
- CursorOff; Cls;
- WriteString("Copying ");
- WriteString(path);
- WriteString(" to ");
- WriteString(newfile);
- WriteLn |
- END;
- RETURN TRUE
- END OpenDevice;
-
- BEGIN
- Printer := unknown;
- path := "A:\*.*";
- OpenAppl(wh);
-
- KeepGoing := TRUE; (* flag used by both PRG and ACC versions *)
- FindDate(year, month, day); FindTime(hour, min, sec); (* for print header *)
- INC(year, 80);
- WHILE KeepGoing DO
- GetDrv(Drive);
- path[0] := CHR( ORD('A') + Drive );
- Ext := "*"; NewPath(path, Ext); (* Ext is a 1-char string *)
- CursorOff; Cls; CursorAddress(wh, 2, 21); ReverseVideoOn(wh);
- WriteString("CAT by WLS: Select INPUT File...");
- ReverseVideoOff(wh); CursorAddress(wh, 12, 40); CursorOn;
- IF SelectFile(path)
- THEN SetDrv(ORD(path[0])-ORD('A'), dummy);
- OpenStream(InStream, path, READ, i);
- IF i >= 0 THEN (* InStream was opened OK *)
- IF OpenDevice() THEN
- Done := NOT EOS(InStream); (* Streams/InOut compatibility *)
- lastchar := normal; dot := 0; (* process initial newlines *)
- WHILE Done DO
- REad(InStream, c);
- pass;
- END;
- IF Device = printer THEN PutByte(ASCII.FF);
- ELSIF Pause (* implies Device = screen *)
- THEN ReverseVideoOn(wh);
- WriteString("---End of File---");
- ReverseVideoOff(wh); NecIn(c);
- CASE c OF
- 'a', 'A', 'q', 'Q' : KeepGoing := FALSE
- ELSE END; (* actually continue! *)
- END;
- CloseStream(InStream, i); IF i<0 THEN Wrap END;
- ELSE Wrap END; (* could we open the Device? *)
- ELSE Wrap END; (* open InStream *)
- CloseStream(OutStream, i); IF i<0 THEN Wrap END;
- ELSE Wrap END; (* no file selected *)
- END; (* WHILE *)
- END Cat.
-